fix(network): support ChangeL2NetworkVlanId for ZNS networks#3723
fix(network): support ChangeL2NetworkVlanId for ZNS networks#3723ZStack-Robot wants to merge 1 commit intofeature-5.5.12-znsfrom
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
Walkthrough该合并请求为 L2 网络 VLAN ID 变更增加了空值/类型归一化检查,修复了 VxLAN 类型比较的 NPE 风险,新增了 L2 网络扩展点的 beforeUpdate 回调及差异化异常处理,并在错误码中添加了两个常量(10016、10017)。 Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
network/src/main/java/org/zstack/network/l2/L2NetworkApiInterceptor.java (1)
147-150: 建议在默认回填前对type做 trim 归一化Line 147-150 目前只处理
null。若传入空白字符串(如" "),不会回填默认类型,可能绕过后续类型分支校验。建议在这里先trimToNull再回填。建议修改
- // When type is not specified, default to the current network type - if (msg.getType() == null) { - msg.setType(l2.getType()); - } + // When type is not specified, default to the current network type + msg.setType(StringUtils.trimToNull(msg.getType())); + if (msg.getType() == null) { + msg.setType(l2.getType()); + }As per coding guidelines "注意检查来自 Message 的参数是否做过 trim,用户可能在浏览器上复制粘贴的数据带有空格、换行符等"。
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@network/src/main/java/org/zstack/network/l2/L2NetworkApiInterceptor.java` around lines 147 - 150, The code in L2NetworkApiInterceptor currently only checks msg.getType() for null before filling the default; update the logic to normalize/trim the incoming type first (e.g., treat blank or whitespace-only strings as null) by using a trim-to-null step on msg.getType() and then call msg.setType(l2.getType()) when the trimmed value is null/empty; locate the handling around msg.getType()/msg.setType() in L2NetworkApiInterceptor and apply the trim-to-null normalization prior to the default-backfill so blank strings don't bypass type validation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@network/src/main/java/org/zstack/network/l2/L2NetworkApiInterceptor.java`:
- Around line 147-150: The code in L2NetworkApiInterceptor currently only checks
msg.getType() for null before filling the default; update the logic to
normalize/trim the incoming type first (e.g., treat blank or whitespace-only
strings as null) by using a trim-to-null step on msg.getType() and then call
msg.setType(l2.getType()) when the trimmed value is null/empty; locate the
handling around msg.getType()/msg.setType() in L2NetworkApiInterceptor and apply
the trim-to-null normalization prior to the default-backfill so blank strings
don't bypass type validation.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: http://open.zstack.ai:20001/code-reviews/zstack-cloud.yaml (via .coderabbit.yaml)
Review profile: CHILL
Plan: Pro
Run ID: 9dfccf31-b657-456c-9192-2285114fdae7
📒 Files selected for processing (3)
network/src/main/java/org/zstack/network/l2/L2NetworkApiInterceptor.javaplugin/vxlan/src/main/java/org/zstack/network/l2/vxlan/vxlanNetworkPool/VxlanNetworkCheckerImpl.javautils/src/main/java/org/zstack/utils/clouderrorcode/CloudOperationsErrorCode.java
318d81c to
ecf5fe8
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@network/src/main/java/org/zstack/network/l2/L2NetworkApiInterceptor.java`:
- Around line 149-152: Normalize and validate the incoming type on
L2NetworkApiInterceptor: instead of only checking msg.getType() == null, trim
the value from msg.getType(), treat empty/blank strings as null and set to
l2.getType() via msg.setType(), and then explicitly reject any unsupported
values (not matching expected enums/types used by the existing branches) with a
clear error; update the logic around msg.getType()/msg.setType() so subsequent
branches that handle VLAN and other type-specific validation (the branches
referenced after this code) cannot be bypassed by blank or unknown type strings.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: http://open.zstack.ai:20001/code-reviews/zstack-cloud.yaml (via .coderabbit.yaml)
Review profile: CHILL
Plan: Pro
Run ID: 2ba1c2f9-9b02-4d7b-998c-4f2809ec0626
📒 Files selected for processing (4)
network/src/main/java/org/zstack/network/l2/L2NetworkApiInterceptor.javanetwork/src/main/java/org/zstack/network/l2/L2NetworkExtensionPointEmitter.javaplugin/vxlan/src/main/java/org/zstack/network/l2/vxlan/vxlanNetworkPool/VxlanNetworkCheckerImpl.javautils/src/main/java/org/zstack/utils/clouderrorcode/CloudOperationsErrorCode.java
✅ Files skipped from review due to trivial changes (1)
- utils/src/main/java/org/zstack/utils/clouderrorcode/CloudOperationsErrorCode.java
🚧 Files skipped from review as they are similar to previous changes (1)
- plugin/vxlan/src/main/java/org/zstack/network/l2/vxlan/vxlanNetworkPool/VxlanNetworkCheckerImpl.java
1522f32 to
fa787f4
Compare
Handle blank or omitted type in APIChangeL2NetworkVlanIdMsg by normalizing to the current L2 type before validation checks. Resolves: ZSTAC-2074 Change-Id: Icf960d0766b726047d8613305042cfa14e120c61
fa787f4 to
e8bc99f
Compare
When type param is null in APIChangeL2NetworkVlanIdMsg, default to current
network type to prevent NPE in interceptors and handlers. Add null-safe
type check in VxlanNetworkCheckerImpl. Add ZNS error codes 10011-10015.
Resolves: ZCF-2074
Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com
sync from gitlab !9593